package com.ns.sbs.oauth.acc.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ns.sbs.oauth.acc.dto.AccPageDto;
import com.ns.sbs.oauth.acc.entry.Account;
import com.ns.sbs.oauth.acc.mapper.Acc2ServerMapper;
import com.ns.sbs.oauth.acc.mapper.AccountMapper;
import com.ns.sbs.oauth.acc.vo.AccCompleteVO;
import com.ns.sbs.oauth.acc.vo.AccVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * Service: admin管理员
 *
 * @author lw
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements IAccountService {

    private final AccountMapper mapper;
    private final Acc2ServerMapper acc2ServerMapper;

    @Override
    public AccCompleteVO getAccById(Long id, Long sid) {
        return mapper.getById(id, sid);
    }

    @Override
    public Page<AccVO> getList(AccPageDto dto) {
        return mapper.getList(dto, new Page<>(dto.getCurrent(), dto.getSize()));
    }

    @Override
    public int deleteByIds(List<Long> ids) {
        return mapper.deleteByIds(ids);
    }

    @Override
    public Long checkAccIdAndPhone(Long accId, String phone) {
        LambdaQueryWrapper<Account> wrapper = new LambdaQueryWrapper<>();
        wrapper.ne(Objects.nonNull(accId), Account::getId, accId).eq(Account::getPhone, phone);
        return mapper.selectCount(wrapper);
    }

    @Override
    public AccCompleteVO getAccByPhone(String phone) {
        return mapper.getByPhone(phone);
    }

    @Override
    public Long checkByPhone(String phone) {
        return mapper.countByPhone(phone);
    }
}
